					**This file runs panel specifications**	

			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**
			**	**	**	**	**	**	**	**	**	**	**	**	**

use removalcounts, clear


*-------------------------------------------------------------------------------
* First we'll do the version with negative binomial regression
*-------------------------------------------------------------------------------


**
*First all
**

glm countymonthlytotal i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls


preserve


* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "All"

* 95% CI
gen ub = coef + 1.96 * stderr * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr * sqrt(deviance/df)

save temp1, replace

restore


**
*Now no convictions
**

glm threat0count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls

preserve


* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "No Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr * sqrt(deviance/df)

save temp2, replace

restore


**
*Now ICE Category 1 convictions
**

glm threat1count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls

preserve 

* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "Category 1 Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr * sqrt(deviance/df)

save temp3, replace

restore


**
*Now violent convictions
**


glm violentcount i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls

preserve

* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "Violent Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr * sqrt(deviance/df)
gen lb = coef - 1.96 * stderr * sqrt(deviance/df)

append using temp1 temp2 temp3


***
*Figure (note: this figure does not appear in paper)
***

gen counter = _n

twoway (rspike ub lb counter , lw(0.3) lc(gray) hor) (scatter counter coef, msize(small) msymbol(circle) ), ///
	xli(0, lpattern(dash) lc(black)) ///
	ylab( 1 "Violent Convictions" 2 "All" 3 "No Convictions" 4 "Category 1 Convictions", labsize(large) angle(horizontal) nogrid) ///
	xlab(-1(.2)1, labsize(large) angle(horizontal)) legend(off) xti("Effect on Log Deportations (95% CI)", size(large)) ///
	yti("") aspect(.5) graphregion(color(white)) ysize(2)
graph export "Comparecoefficients.pdf", replace

restore


*-------------------------------------------------------------------------------
* Now same with linear regression and logged dependent variable
*-------------------------------------------------------------------------------


**
*First all
**

areg logcountymonthlytotal i.month monthlysanctuary, absorb(statecounty) ///
cluster(state) 


preserve


* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "All"

* 95% CI
gen ub = coef + 1.96 * stderr
gen lb = coef - 1.96 * stderr 

save temp1, replace

restore


**
*Now no convictions
**

areg logthreat0count i.month monthlysanctuary, absorb(statecounty) ///
cluster(state) 

preserve


* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "No Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr
gen lb = coef - 1.96 * stderr

save temp2, replace

restore


**
*Now ICE Category 1 convictions
**

areg logthreat1count i.month monthlysanctuary, absorb(statecounty) ///
cluster(state) 

preserve 

* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "Category 1 Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr
gen lb = coef - 1.96 * stderr 

save temp3, replace

restore


**
*Now violent convictions
**


areg logviolentcount i.month monthlysanctuary, absorb(statecounty) ///
cluster(state) 

* Get coef
regsave  monthlysanctuary, detail(all)

* Rename
replace var = "Violent Convictions"

* 95% CI
gen ub = coef + 1.96 * stderr 
gen lb = coef - 1.96 * stderr

append using temp1 temp2 temp3


***
*Figure S9
***
gen counter = _n



twoway (rspike ub lb counter , lw(0.3) lc(gray) hor) (scatter counter coef, msize(small) msymbol(circle) ), ///
	xli(0, lpattern(dash) lc(black)) ///
	ylab( 1 "Violent Convictions" 2 "All" 3 "No Convictions" 4 "Category 1 Convictions", labsize(large) angle(horizontal) nogrid) ///
	xlab(-1(.2)1, labsize(large) angle(horizontal)) legend(off) xti("Effect on Log Deportations (95% CI)", size(large)) ///
	yti("") aspect(.5) graphregion(color(white)) ysize(2)
	
graph export "s9.pdf", replace


*-------------------------------------------------------------------------------
* Now negative binomial regression for table
*-------------------------------------------------------------------------------

use removalcounts, clear

_eststo clear
**
*First all
**

eststo: glm countymonthlytotal i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls


**
*Now no convictions
**

eststo: glm threat0count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls


**
*Now ICE Category 1 convictions
**

eststo: glm threat1count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls


**
*Now violent convictions
**

eststo: glm violentcount i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls


***
*Table 2 (note that SEs need to be fixed below)
***

esttab using "table2.tex", se mti("All" "None" "Category 1" "Violent") ti("Difference-in-Difference Estimates: Effect of Sanctuary on Deportations") /// 
coef(monthlysanctuary "Sanctuary" _cons "Intercept") ///
addn("Includes County and Month Fixed Effects; Standard Errors Clustered on State") ///
keep(monthlysanctuary _cons) replace

****
***
**Now we need to fix SEs and substitute them in the table
***
****

**
*First all
**

eststo: glm countymonthlytotal i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls
regsave  monthlysanctuary, detail(all)
gen se = (stderr * sqrt(deviance/df))
tab se

**
*Now no convictions
**

use removalcounts, clear

eststo: glm threat0count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls
regsave  monthlysanctuary, detail(all)
gen se = (stderr * sqrt(deviance/df))
tab se

**
*Now ICE Category 1 convictions
**

use removalcounts, clear
eststo: glm threat1count i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls
regsave  monthlysanctuary, detail(all)
gen se = (stderr * sqrt(deviance/df))
tab se

**
*Now violent convictions
**

use removalcounts, clear
eststo: glm violentcount i.month i.statecounty monthlysanctuary, family(nbinomial ml) ///
cluster(state) link(log) irls
regsave  monthlysanctuary, detail(all)
gen se = (stderr * sqrt(deviance/df))
tab se
